<?php
/**
 * 随租随还
 * User: tengyu
 * Date: 2017/10/30
 * Time: 13:22
 */?>
@extends('common.common')
@section('title',$param['title'])
@section('css')<link rel="stylesheet" href="{{asset('/css/applyService_sui.css')}}">@endsection
@section('js')
    <script>
        /**
         * 商品下单数量变更-
         * @cartid当前在租订单详情id
         */
        function decreback(cartid)
        {
            var num = $("#rentback_num").text();
            var rentback_num = $("input[name='rentback_num']").val();
            if(num-1<1){
                alert('退租数量已达下限');
            }else{
                num = num-1;
                $("#rentback_num").text(num);
            }
        }
        /**
         * 商品下单数量变更+
         * @cartid当前在租订单详情id
         */
        function increback(cartid)
        {
            var rentback_num = parseInt($("input[name='rentback_num']").val());
            var num = parseInt($("#rentback_num").text());
            num = num+1;
            if(num>rentback_num){
                alert('退单数量超出当前在租数量!');
                return false;
            }else{
                $("#rentback_num").text(num);
            }
        }

        /**处理退租逻辑【随租】*/
        function dorentback_type_nimb()
        {
            /**订单id*/
            var order_id = $("input[name='order_id']").val();
            /**退租订单详情id*/
            var order_details_id = $("input[name='order_details_id']").val();
            /**退租订单详情单号*/
            var details_orderNo = $("input[name='details_orderNo']").val();
            /**退租商品id*/
            var fitment_details_id = $("input[name='details_fitment_id']").val();
            /**退租商品数量*/
            var fitment_details_number = $("#rentback_num").text();
            /**商品租满即送租金*/
            var rentback_fix = $("input[name='rentback_fix']").val();
            /**商品随租租金*/
            var rentback_nimb = $("input[name='rentback_nimb']").val();
            /**商品所需信用额度值*/
            var rentback_bond = $("input[name='rentback_bond']").val();
            /**收货地址id*/
            var adr_id = $("input[name='adr_id']").val();
            /***退租去向【退租去向,1退租,2转随租,3转租满即送】*/
            var outrent_type = 1;
            var outrent_bill = null;
            var outrent_bond = null;
            var outrent_amount = null;
            $.ajax({
                url:'/user/dorentback',
                type:'post',
                headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                data:{
                    'type':1,
                    'order_id':order_id,'order_details_id':order_details_id,'details_orderNo':details_orderNo,'fitment_details_id':fitment_details_id,
                    'fitment_details_number':fitment_details_number,'adr_id':adr_id,'outrent_type':outrent_type,'details_rent_type':1,
                    'rentback_fix':rentback_fix,'rentback_nimb':rentback_nimb,'rentback_bond':rentback_bond,
                    'outrent_bill':outrent_bill,'outrent_bond':outrent_bond,'outrent_amount':outrent_amount
                },
                dataType:'json',
                success:function(res){
                    if(res.res=='ok'){
                        alert(res.msg);
                        history.go(0);
                    }else{
                        alert(res.msg);
                    }
                }
            });
        }
    </script>
@endsection
@section('content')
    <div id="content">
        @include('common.centernav')
        <h3>个人中心</h3>
        <div class="container">
            <div class="row">
            @include('usercenter.usersidebar')
                <!--2、右侧主体-->
                <div class="col-xs-9">
                    <!--右侧面版-->
                    <div id="panel" class="panel panel-default rightPanel">
                        <div class="panel-heading">
                            <h4 class="myorder">申请退租(随租随还)</h4>
                        </div>
                        <div class="panel-body">
                            <ul class="product list-inline">
                                <li>商品信息</li>
                                <li>订单金额</li>
                                <li>时长</li>
                                <li>退租数量</li>
                                <li>操作</li>
                            </ul>
                            @if(is_object($param['rentback_dt']))
                            <p class="productDate">
                                <span>下单日期:</span>
                                <span>{{substr($param['rentback_dt']->created_at,0,10)}}</span>&nbsp;&nbsp;
                                <span>订单号:</span>
                                <span>{{$param['rentback_dt']->details_orderNo}}</span>&nbsp;&nbsp;
                                <span>起租日期:</span>
                                <span>{{$param['rentback_dt']->details_fitment_start}}</span>
                                <a class="rt" href="{{url('/user/orderdt/'.$param['rentback_dt']->id)}}">订单详情</a>
                            </p>
                                <input type="hidden" name="order_id" value="{{$param['rentback_dt']->id}}">
                                <input type="hidden" name="order_details_id" value="{{$param['rentback_dt']->dtid}}">
                                <input type="hidden" name="details_orderNo" value="{{$param['rentback_dt']->details_orderNo}}">
                                <input type="hidden" name="details_orderNo" value="{{$param['rentback_dt']->details_orderNo}}">
                                <input type="hidden" name="details_fitment_id" value="{{$param['rentback_dt']->details_fitment_id}}">
                                <input type="hidden" name="rentback_num" value="{{$param['rentback_dt']->details_fitment_number}}">
                                <input type="hidden" name="rentback_fix" value="{{$param['rentback_dt']->details_fixprice}}">
                                <input type="hidden" name="rentback_nimb" value="{{$param['rentback_dt']->details_nimbleprice}}">
                                <input type="hidden" name="rentback_bond" value="{{$param['rentback_dt']->details_bond}}">
                                <input type="hidden" name="adr_id" value="{{$param['rentback_dt']->adr_id}}">
                                <ul class="orders list-inline">
                                <li class="imgInfo">
                                    <div class="media">
                                        <div class="media-left">
                                            <img src="{{asset(env('STATIC_FILE_ERP_PATH').$param['rentback_dt']->fitment_details_imgMaster)}}" style="width: 151px;height: 92px;">
                                        </div>
                                        <div class="media-body">
                                            <p>{{$param['rentback_dt']->details_name}}</p>
                                            <p>
                                            <?php
                                            $color=DB::table('fitment_color')->where('color_details_id',$param['rentback_dt']->details_fitment_id)->select('color_type')->get();
                                            ?>
                                            @foreach($color as $color_k=>$color_v)
                                                <img src="{{$param['color'][$color_v->color_type]}}" alt="当前家具颜色">
                                            @endforeach
                                            </p>
                                            <p>¥<span>{{$param['rentback_dt']->details_nimbleprice}}</span>/月</p>
                                        </div>
                                    </div>
                                </li>
                                <li>¥{{$param['rentback_dt']->details_nimbleprice*$param['rentback_dt']->details_fitment_number}}</li>
                                <li><span>12</span>个月</li>
                                <li class="number">
                                    <b class="glyphicon glyphicon-minus-sign" onclick="decreback({{$param['rentback_dt']->id}})"></b>
                                    <span id="rentback_num">{{$param['rentback_dt']->details_fitment_number}}</span>
                                    <b class="glyphicon glyphicon-plus-sign" onclick="increback({{$param['rentback_dt']->id}})"></b>
                                </li>
                                <li>
                                    <span onclick="alert('删除功能需求还没确定')">&times;</span>
                                </li>
                            </ul>
                            <div class="rent">
                                <p>退租类型（随租随还）</p>
                                <p>随租随还产品退租，剩余押金<span>{{$param['rentback_dt']->details_fitment_number*$param['rentback_dt']->details_nimbleprice*2}}</span>元，将退回平台账户</p>
                            </div>
                            @endif
                            <p class="productDate border">未还款账单</p>
                            <ul class="list-inline noHead">
                                <li>还款期</li>
                                <li>时间</li>
                                <li>当前租金</li>
                            </ul>
                            @if(count($param['rentback_bill'])>0)
                            @foreach($param['rentback_bill'] as $v)
                            <ul class="list-inline noBody">
                                <li>{{substr($v->months_bill,0,7)}}</li>
                                <li><span>12</span>个月</li>
                                <li class="red">¥<span>{{$v->amount}}</span></li>
                            </ul>
                            @endforeach
                            @else
                            <ul class="text-center">
                                <img src="{{asset('/img/771509094256_.pic.jpg')}}" alt="暂无未付款记录">
                            </ul>
                            @endif
                            <p class="productDate border">
                                退租说明
                            </p>
                            <div class="introduce">
                                <p>对于"随租随还"的产品：</p>
                                <p>若您有退租需求可随时退租，但需缴纳退租产品的所有使用租金，芈租界会将产品押金退还至您的平台账户，可随时申请提现。</p>
                                <br>
                                <p>对于"租满即送"的产品：</p>
                                <p>若您有退租需求可进行申请，但视为违约行为，需向芈租界缴纳剩余未缴纳但租金5%作为违约金。</p>
                            </div>
                            <div class="btnName">
                                <a class="btn btn-danger" onclick="dorentback_type_nimb()">确认退租</a>
                                <a class="btn btn-warning" onclick="alert('等待研发')">联系客服</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
